package com.yyd.designmodel.observer.impl;

import com.yyd.designmodel.observer.Watched;
import com.yyd.designmodel.observer.Watcher;

/**
 * 
 * @Description：[ 观察者测试类 ]
 *
 * @ProjectName：[designmodel]
 * @PackageName：[com.yyd.designmodel.observer.impl.Observer]
 * @CreateDate：[2015-1-20  上午9:22:55] 
 * @Author：[yuyidi]
 */
public class Observer {
    
    public static void main(String[] args) {
//        Watched watched = new ConcreteWatched();
//        Watcher watcher1 = new ConcreteWatcher();
//        Watcher watcher2 = new ConcreteWatcher();
//        Watcher watcher3 = new ConcreteWatcher();
//        watched.addWatcher(watcher1);
//        watched.addWatcher(watcher2);
//        watched.addWatcher(watcher3);
//        watched.notifyWatcher("观察者");
        //四个读者
        Reader r1 = new Reader("谢广坤");
        Reader r2 = new Reader("赵四");
        Reader r3 = new Reader("七哥");
        Reader r4 = new Reader("刘能");
        //两个作者
        Writer w1 = new Writer("谢大脚");
        Writer w2 = new Writer("王小蒙");
        //四个人都关注了谢大脚
        r1.subscribe("谢大脚");
        r2.subscribe("谢大脚");
        r3.subscribe("谢大脚");
        r4.subscribe("谢大脚");
        
        //七哥和刘能还关注了王小蒙
        r3.subscribe("王小蒙");
        r4.subscribe("王小蒙");
        
        w1.addNovel("设计模式");
        w2.addNovel("java编程思想");
        
        r1.unsubscribe("谢大脚");
        w1.addNovel("观察者模式");
    }
}
